package com.zzy.collection.jdk8sort;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import org.junit.Test;

public class ListTest {
	@Test
	public void test() throws ParseException {
		List<Student> stuList = new ArrayList<Student>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
		stuList.add(new Student("wang", "18", sdf.parse("2007/04/01")));
		stuList.add(new Student("li", "17", sdf.parse("2007/05/06")));
		stuList.add(new Student("liu", "20", sdf.parse("2006/04/01")));
		stuList.add(new Student("xi", "15", sdf.parse("2007/04/01")));
		stuList.add(new Student("li", "17", sdf.parse("2007/05/01")));
		stuList.add(new Student("wang", "19", sdf.parse("2007/06/01")));



		// named不分区大小写降序
		Comparator<Student> byNameDESC = Comparator.comparing(Student::getName, String.CASE_INSENSITIVE_ORDER).reversed();
		
		// age升序
		Comparator<Student> byAgeASC = Comparator.comparing(Student::getAge);
		
		// birthday 降序
		Comparator<Student> byBirthdayDESC = Comparator.comparing(Student::getBirthday).reversed();

		// 联合排序
		Comparator<Student> finalComparator = byNameDESC.thenComparing(byAgeASC).thenComparing(byBirthdayDESC);

		List<Student> result = stuList.stream().sorted(finalComparator).collect(Collectors.toList());

		this.printList(result);

	}

	public void printList(List<Student> result) {
		for (Student student : result) {
			System.out.println(student);
		}
	}

}